package com.example.myengine.myrule;

import com.example.myengine.engine.LogicFilter;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ycd0075
 * @date 2024-02-04 14:50
 */
@Component
public class RuleFilterManager implements ApplicationContextAware {

    private Map<String, LogicFilter> logicFilterMap = new HashMap<>();


    public Map<String, LogicFilter> getLogicFilterMap() {
        return logicFilterMap;
    }

    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        Map<String, LogicFilter> map = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, LogicFilter.class);
        map.forEach((k, v) -> logicFilterMap.put(v.filterType(), v));
    }
}
